class Solution(object):
    def findNthDigit(self, n):
        """
        :type n: int
        :rtype: int
        """
        if n <= 9:
            return n

        i = 1 # 每一段数字的长度
        b = 9 # 每一段数字的数目
        p = 0 # 已经超过的数字段

        while n > i * (pow(10, i) - pow(10, i - 1)):
            b = pow(10, i) - pow(10, i - 1)
            p += b
            n = n - (i * b)
            i += 1

        num = p + ((n - 1) // i) + 1

        return int(list(str(num))[(n - 1) % i])
        
s = Solution()
print(s.findNthDigit(3))
print(s.findNthDigit(11))
print(s.findNthDigit(189))
print(s.findNthDigit(190))
